package com.libgdxbar.pvzlikegame;

import com.badlogic.gdx.assets.AssetManager;

public class AssetsLoader {
	private static AssetsLoader instance;
	private final AssetManager assetManager = new AssetManager();

	public static synchronized AssetsLoader getInstance() {
		if (instance == null) {
			instance = new AssetsLoader();
		}
		return instance;
	}

	// 直接同步加载 简单但效率不高
	// DONE 实现异步加载功能
	public <T> T get(String fileName, Class<T> type) {
		if (!assetManager.isLoaded(fileName, type)) {
			assetManager.load(fileName, type);
			assetManager.finishLoading();
		}
		return assetManager.get(fileName, type);
	}

	public void dispose() {
		assetManager.dispose();
	}

}
